#include once "mud-gui/ui.bi"
#include once "mud-gui/widgets/CustomLayout.bi"
#include once "mud-gui/widgets/PushButton.bi"
#include once "mud-gui/widgets/Dialog.bi"
#include once "mud-gui/widgets/GridLayout.bi"
#include once "mud-gui/widgets/PushButton.bi"
#include once "fbgfx.bi"

using ui

SLOT(pbhandler)
return -1
ENDSLOT

SLOT(click_handler)
var dlg = new Dialog(,320,240)
var mw = new GridLayout(toBaseWidget(dlg))

dlg->init

var label1 = new label
label1->setText = "Label 1"

var label2 = new label
label2->setText = "Label 2"

var label3 = new label
label3->setText = "Label 3"

var label4 = new label
label4->setText = "Label 4"

var label5 = new label
label5->setText = "Label 5"

var pb = new PushButton
'connectSignal(pb,clicked,pbhandler)

mw->sizeGrid(4,4)

ConsolePrint( "1: " & mw->placeWidget( toBaseWidget(label1), 1, 1 ) )
mw->placeWidget( toBaseWidget(pb) ,1 ,2 )
ConsolePrint( "2: " & mw->placeWidget( toBaseWidget(label2), 2, 2 ) )
ConsolePrint( "3: " & mw->placeWidget( toBaseWidget(label3), 3, 2, 4, 4 ) )
ConsolePrint( "4: " & mw->placeWidget( toBaseWidget(label4), 3, 1, 4, 1 ) )
ConsolePrint( "5: " & mw->placeWidget( toBaseWidget(label5), 1, 3, 2, 4 ) )


dlg->addButton(toBaseWidget(pb),MG_CANCEL)
ConsolePrint( "dlg ret: " & dlg->run() )
delete dlg
return false

ENDSLOT

if initScreen("CustomLayout Example", 640, 480 ) = 0 then
        print "unable to initialize screen."
        end 23
end if
var paintevent = new _GUI_EVENT_
var cl = new CustomLayout
cl->setXpos = 0
cl->setYpos = 0
cl->setWidth = 640
cl->setHeight = 480

var pb1 = new PushButton
connectSignal(pb1,clicked,click_handler)

var pb2 = new PushButton
cl->placeWidget( toBaseWidget(pb1),  98, 309, 114, 43 )
cl->placeWidget( toBaseWidget(pb2), 369, 394, 142, 50 )
paintevent->id = gevent.resize
sendEvent( toBaseWidget(cl), paintevent )
dim as fb.image ptr bgImage
bgImage = imagecreate( 640, 480 )
bload exepath & "/clbg.bmp", bgImage
put (0,0), bgImage, trans
paintevent->id = gevent.repaint
while stepMain( toBaseWidget(cl) ) = 0
        screenlock
        cls
        SendEvent( toBaseWidget(cl), paintevent )
        put (0,0), bgImage, trans
        screenunlock
wend
imagedestroy bgImage
delete paintevent
delete cl
